#include "map.h"
#include <QtMath>

Map::Map()
{
    //加载地面资源
    m_Map.load(GROUND_PATH);

    //地面坐标
    m_X = 0;
    m_Y = 0;

    //地面速度
    m_Speed = GROUND_SPEED;

    //地面块边框
    m_Rect.setWidth(m_Map.width());
    m_Rect.setHeight(m_Map.height());
    m_Rect.moveTo(m_X,m_Y);

}

void Map::updatePosition()
{
    m_X -= m_Speed;
    m_Rect.moveTo(m_X,m_Y);
}
Ground::Ground()
{
    for(int i=0;i < 17;i++)
    {
        grounds[i].m_X = grounds[i].m_Map.width()*i;
        grounds[i].m_Y = GAME_HEIGTH - grounds[i].m_Map.height();
        grounds[i].m_Rect.moveTo(grounds[i].m_X,grounds[i].m_Y);
    }
}
void Ground::updatePositions()
{
    for(int i=0;i<17;i++)
    {
        grounds[i].updatePosition();
        if(grounds[i].m_X <= -grounds[i].m_Map.width())
        {
            //强制对齐（为了无缝）
            int prevIndex = (i==0)? 16 : i-1;
            grounds[i].m_X = qRound(static_cast<double>(grounds[prevIndex].m_X + grounds[prevIndex].m_Map.width()));
            grounds[i].m_Rect.moveTo(grounds[i].m_X,grounds[i].m_Y);
        }
    }
}
